package com.search.controller;

import com.search.service.impl.SearchServiceImpl;
import com.search.vo.SearchParam;
import com.search.vo.SearchResult;
import org.elasticsearch.search.SearchService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.sql.ResultSet;
import java.util.List;

/**
 * @Author Rookie-6688
 * @Description
 * @Create 2021-04-02 15:38
 */
@Controller
public class SearchController {

    @Resource
    SearchServiceImpl searchServiceImpl;

    @GetMapping("/list.html")
    public String list(SearchParam searchParam, Model model, HttpServletRequest request){
        // 将 URL 中 ? 后的请求部分存储属性中，为了后面设置面包屑时可以对URL进行替换设置
        // http://search.gulimall.com/list.html?keyword=华为
        searchParam.set_queryString(request.getQueryString());
        SearchResult result = searchServiceImpl.search(searchParam);
        model.addAttribute("result", result);
        return "list";
    }
}
